package com.efast.dmom.mes.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.efast.dmom.mes.bean.QualityDefectGroup;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.datahandlers.entity.QualityDefectGroupHandler;
import com.efast.dmom.mes.service.QualityDefectGroupService;
@Service
public class QualityDefectGroupServiceImpl implements QualityDefectGroupService {

	@Autowired
	private QualityDefectGroupHandler qualityDefectGroupHandle = null;
	@Override
	public ResultBean save(QualityDefectGroup qualityDefectGroup) {
		ResultBean resultBean = new ResultBean(true);
		List<QualityDefectGroup> list = new ArrayList<QualityDefectGroup>();
		list.add(qualityDefectGroup);
		List<QualityDefectGroup> byDefectId = qualityDefectGroupHandle.getByDefectIdAndGroupId(list);
		if (byDefectId != null && byDefectId.size() > 0) {
			resultBean.setSuccess(false);
			resultBean.setMessage("当前不良已存在，请重新选择！");
			return resultBean;
		}
		qualityDefectGroupHandle.save(qualityDefectGroup);
		return resultBean;
	}

	@Override
	public ResultBean update(QualityDefectGroup qualityDefectGroup) {
		ResultBean resultBean = new ResultBean(true);
		qualityDefectGroupHandle.update(qualityDefectGroup);
		return resultBean;
	}

	@Override
	public ResultBean delete(QualityDefectGroup qualityDefectGroup) {
		ResultBean resultBean = new ResultBean();
		return resultBean;
	}

	@Override
	public ResultBean batchDeleteById(List<QualityDefectGroup> list) {
		ResultBean resultBean = new ResultBean(true);
		qualityDefectGroupHandle.batchDeleteByIds(list);
		return resultBean;
	}

	@Override
	public ResultBean getById(long id) {
		ResultBean resultBean = new ResultBean(true);
		qualityDefectGroupHandle.getById(id);
		return resultBean;
	}

}
